package com.ct.gd.passport.view.exhibition;

import java.util.List;

import android.os.Bundle;

import com.ct.gd.passport.R;
import com.ct.gd.passport.common.BaseActivity;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Config.Area;
import com.ct.gd.passport.view.LocationFragment;
import com.ct.gd.passport.view.LocationFragment.OnLocationChangedListener;
import com.ct.gd.passport.view.LocationFragment.OnLocationsLoadedListener;
import com.ct.gd.passport.view.widget.CustomHeaderFragment;

public class ExhibitionActivity extends BaseActivity implements OnLocationChangedListener, OnLocationsLoadedListener {
	private static final String		TAG_LOCATION_FRAGMENT	= "TAG_LOCATION_FRAGMENT";
	
	private CustomHeaderFragment	mFgHeader;
	private LocationFragment		mFgLocation;
	private ExhibitionInfoFragment		mExhibitionInfoFragment;

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.exhibition);
	}

	@Override
	protected void initViews() {
		mFgHeader = (CustomHeaderFragment) getFragmentManager().findFragmentById(R.id.header);
		mFgHeader.setCenterText(Config.currentArea.name);
		
		mFgLocation = new LocationFragment();
		getSupportFragmentManager().beginTransaction().add(mFgLocation, TAG_LOCATION_FRAGMENT).commit();
		
		mExhibitionInfoFragment = (ExhibitionInfoFragment) getFragmentManager().findFragmentById(R.id.exhibition_frag);
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		mFgLocation.registerOnLocationChangedListener(this);
		mFgLocation.registerOnLocationsLoadedListener(this);
	}

	@Override
	public void onLocationsLoaded(List<Area> areas) {
		mFgHeader.setCenterView(mFgLocation.getView());
	}

	@Override
	public void onLocationChanged(Area area) {
		mFgLocation.getLocationTextView().setText(area.name);
		Config.currentArea = area;
		
		mExhibitionInfoFragment.loadCatalog();
	}

}
